<template>
  <scroll-view class="coupon-scroll" scroll-x="true">
    <view class="coupon-item" v-for="(item, index) in couponList" :key="index">
      <view class="coupon-content">
        <view class="price">
          <text :style="{ color: priceColor }" v-if="item.discount_type != 1"
            >￥</text
          >
          <text :style="{ color: priceColor }" v-if="item.discount_type != 1">{{
            item.sub_price | subStrToInt
          }}</text>
          <text
            v-if="item.discount_type == 1"
            :style="{ color: priceColor, fontSize: '54rpx' }"
            >{{ item.discount }}折</text
          >
        </view>
        <view class="coupon-info">
          <view class="coupon-title" :style="{ color: infoColor }">{{
            item.name
          }}</view>
          <view class="coupon-date" :style="{ color: infoColor }">{{
            item.expire_type != 1
              ? item.begintime + "-" + item.endtime
              : "领取" + item.expire_day + "天后失效"
          }}</view>
        </view>
        <view
          :class="['coupon-receive', item.is_receive == 1 ? 'has-receive' : '']"
          @click.stop="toGetCoupon(item)"
        >
          <view :style="{ color: btnColor }">{{ item.receive_content }}</view>
        </view>
      </view>
      <view class="coupon-bg">
        <image lazy-load :src="propsData.params.couponPic" mode="aspectFill" />
      </view>
    </view>
  </scroll-view>
</template>

<script>
export default {
  props: {
    propsData: {
      type: Object,
      default: () => {
        return {};
      },
    },
    couponList: {
      type: Array,
      default: [],
    },
  },

  computed: {
    priceColor() {
      return this.propsData.params.colorConfig.priceColor;
    },
    infoColor() {
      return this.propsData.params.colorConfig.infoColor;
    },
    btnColor() {
      return this.propsData.params.colorConfig.btnColor;
    },
  },
  filters: {
    subStrToInt(val) {
      val = parseFloat(val);
      return val;
    },
  },
  methods: {
    toGetCoupon(item) {
      if (item.is_receive != 0) return;
      this.$emit("toGetCoupon", { item });
    },
  },
};
</script>

<style scoped lang="scss">
.coupon-scroll {
  width: 93.6%;
  white-space: nowrap;
  margin: 0 auto;
  .coupon-item {
    width: 100%;
    position: relative;
    height: 23.534vw;
    display: inline-block;
    margin-right: 3.2vw;
    .coupon-content {
      width: 100%;
      height: 23.534vw;
      display: flex;
      align-items: center;
      justify-content: space-between;
      position: absolute;
      left: 0;
      top: 0;
      z-index: 11;
      padding-left: 10.25%;
      padding-right: 5.7%;
      overflow: hidden;
      .price {
        display: flex;
        align-items: baseline;
        line-height: 1;
        text:first-child {
          font-size: 32rpx;
          color: #ec2827;
        }
        text:last-child {
          color: #ec2827;
          font-size: 60rpx;
          font-weight: bold;
        }
      }
      .coupon-info {
        position: absolute;
        left: 43.3%;
        top: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: flex-start;

        view {
          width: 100%;
        }

        .coupon-title {
          font-size: 32rpx;
          font-family: PingFang SC;
          font-weight: bold;
          color: #ffffff;
          // max-width: 50.33%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .coupon-date {
          font-size: 28rpx;
          font-family: PingFang SC;
          font-weight: 400;
          color: #ffffff;
          margin-top: 5rpx;
          // max-width: 50.33%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
      .coupon-receive {
        width: 124rpx;
        height: 124rpx;
        background: linear-gradient(
          180deg,
          #ffefd0 0%,
          #ffe2b6 50%,
          #fed59b 100%
        );
        border-radius: 50%;
        display: flex;
        justify-content: center;
        align-items: center;
        position: relative;
        z-index: 111;
        view {
          width: 65rpx;
          font-size: 32rpx;
          font-family: PingFang SC;
          font-weight: 400;
          color: #ec2827;
          white-space: pre-wrap;
          word-wrap: break-word;
          word-break: break-all;
        }
      }
      .has-receive {
        width: 124rpx;
        height: 124rpx;
        background: linear-gradient(
          180deg,
          #ffefd0 0%,
          #ffe2b6 50%,
          #fed59b 100%
        );
        border-radius: 50%;
        opacity: 0.8;
        view {
          width: 100%;
          text-align: center;
        }
      }
    }
    .coupon-bg {
      width: 100%;
      height: 100%;
      image {
        width: 100%;
        height: 100%;
        display: block;
      }
    }
  }
  .coupon-item:last-child {
    margin-right: 0;
  }
}
</style>
